﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Windows.Forms;

namespace MMVoiceComm
{
    class Logger
    {
        static string path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) +
                              "\\MediaMonkey\\MMVoiceComm\\";
        public static void log(string infoToLog)
        {
            try
            {
                
                if (
                    !Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) +
                                      "\\MediaMonkey\\MMVoiceComm\\"))
                {
                    Directory.CreateDirectory(
                        Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) +
                        "\\MediaMonkey\\MMVoiceComm\\");
                }
                if (!File.Exists(path+"log.txt"))
                {
                    File.Create(path + "log.txt");
                }
                if (!File.Exists(path+"DONOTLOG")) 
                File.AppendAllText(
                    Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) +
                    "\\MediaMonkey\\MMVoiceComm\\log.txt", DateTime.Now.ToString() + ":" + infoToLog + "\r\n\n");
            }catch(Exception e)
            {
                MessageBox.
                    Show("Could not log data:"+infoToLog);
            }
        }
        public static Boolean isEnabled()
        {
            if (!File.Exists(path+"DONOTLOG"))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public static void setEnabled(Boolean enabled)
        {
            if (!enabled)
            {
                File.Create(path + "DONOTLOG");
            }
            else
            {
                if (File.Exists(path + "DONOTLOG"))
                {
                    File.Delete(path + "DONOTLOG");
                }
            }
        }
    }
}
